function stringify(obj, sep = '&', eq = '=', names = []) {
    return Object.keys(obj).map(key => {
        const value = obj[key];
        if (value === null) return '';
        if (Array.isArray(value)) {
            const result = [];
            for (let singleValue of value) {
                const singleName = names.length > 0 ? names.concat(key) : key;
                result.push((Array.isArray(singleValue) ? stringify(singleValue, sep, eq, [singleName]) :
                    encodeURIComponent(singleName) + eq + encodeURIComponent(singleValue)));
            }
            return result.join(sep);
        } else {
            const namePrefix = names.length > 0 ? names.concat(key).join('[') + ']' : key;
            return encodeURIComponent(namePrefix) + eq + encodeURIComponent(value);
        }
    }).filter(x => x.length > 0).join(sep);
}